<!--
* description: 展车订单制作-车联网激活
* author: wangjuan
* createdDate:
-->
<template>
  <section class="carActivate">
    <el-dialog
      v-dialogDrag
      :visible="popupsVisible"
      :append-to-body="true"
      width="70%"
      :close-on-click-modal="false"
      @close="close"
    >
      <dialogHeader slot="title" :title="topName" :style-type="$store.state.app.dialogType" />
      <div class="filter-container filter-params">
        <el-row ref="vailComponentList" :gutter="26">
          <component
            :is="comp.component"
            v-for="comp in tableComponents.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire+ comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :parent-fileds="comp.parentFileds"
            :code="formField[comp.codeField]"
            :disabled="comp.disabled"
            :o-fields="comp.oFields"
            :options="comp.options"
            :custom-obj="comp.customObj"
            :is-require="comp.isRequire"
            :is-mul="comp.isMul"
            :span="comp.span || 8"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :date-options-type="comp.dateOptionsType"
            :data-to-object="comp.dataToObj"
            @changeCode="getComponentCode"
          />
        </el-row>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          :icon="comp.icon"
          :fixed="true"
          @click="comp.clickEvent"
        >{{ comp.text }}</el-button>
      </div>
    </el-dialog>
  </section>
</template>
<script>

import { formMixins } from '@/components/mixins/formMixins'
import api from '@/api/belowInfo'
export default {
  components: {
    dialogHeader: () => import('@/components/dialogHeader') // 弹窗标题
  },
  // 组件混入对象
  mixins: [formMixins],

  props: {
    popupsVisible: { type: Boolean, default: false },
    dataForForm: { type: Object, default: () => {} },
    editData: { type: Object, default: () => {} }
  },

  data() {
    return {
      transferOrderDId: '', // 订单字表id
      updateControlIdOd: '', // 并发字段id
      topName: '车主信息',

      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          icon: 'iconfont icon-confirm',
          clickEvent: () => this.save(),
          text: '激活',
          position: 'right'
        },
        {
          compKey: 'btnKey2',
          size: 'small',
          icon: 'iconfont icon-cancel',
          clickEvent: () => this.close(),
          text: this.$t('sys.button.cancel'),
          position: 'right'
        }
      ],

      tableComponents: [
        {
          compKey: 'compKey1',
          labelName: '客户姓名：',
          codeField: 'signatoryname',
          disabled: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isRequire: true,
          isMul: false,
          isMust: true,
          span: 9
        },
        {
          compKey: 'compKey2',
          labelName: '联系电话：',
          codeField: 'signatoryphone',
          validrule: { isPhone: true, maxlength: 11 },
          disabled: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isRequire: true,
          isMul: false,
          isMust: true,
          span: 8
        },
        {
          compKey: 'compKey3',
          isComponent: true,
          labelName: '身份证正面：',
          codeField: 'fileAId',
          component: () => import('@/components/upload/imgUpload'),
          isMust: true,
          span: 8,
          dataToObj: {
            fileUrl: '/mp/file/notice/upload.do'
          },
          sendCode: () => { },
          focusCode: () => { },
          changeCode: () => {}
        },
        {
          compKey: 'compKey4',
          isComponent: true,
          labelName: '身份证反面：',
          codeField: 'fileBId',
          component: () => import('@/components/upload/imgUpload'),
          isMust: true,
          span: 8,
          dataToObj: {
            fileUrl: '/mp/file/notice/upload.do'
          },
          sendCode: () => { },
          focusCode: () => { }
        }
      ],
      // 表单数据（无需赋值，由混入对象赋值）
      formField: {
        VIN: '',
        signatoryname: '',
        signatoryphone: '',
        fileAId: '',
        fileBId: ''
      }
    }
  },

  created() {},
  mounted() {
    this.formField.VIN = this.editData.VIN
    this.formField.signatoryname = this.editData.signatoryname
    this.formField.signatoryphone = this.editData.signatoryphone
  },

  methods: {
    // 激活
    save() {
      this.$requestAPI({
        apiUrl: api.updateExhibitionCar.APIUrl,
        variables: { ...this.formField }
      }).then(response => {
        if (response.result === '0') {
          if (response.msg) {
            this.$message({
              message: response.msg,
              type: 'warn',
              uration: 2000
            })
          }
          return
        }
        this.$message({ message: response.msg })
        this.close(1)
      })
    },
    // 关闭弹窗
    close(type) {
      this.$emit('closecarActivate', type)
    }
  }
}
</script>
<style scoped>

.promptSpan{
  position: absolute;
  bottom: 26px;
  right: 335px;
  color: #e70020;
}

</style>

